﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace Microsoft.WindowsAzure.Search
{
    public class Filter
    {
        private static String[] Stopwords = {"a", "an", "and", "are", "as", "at", "be", "by",
                                        "for", "from", "has", "he", "in", "is", "it",
                                        "its", "of", "on", "that", "the", "to", "was",
                                        "were", "will", "with"};

        public static void StopwordFilter(List<String> tokens)
        {
            List<String> tokensCopy = new List<String>();
            tokensCopy.AddRange(tokens);

            foreach (String token in tokensCopy)
            {
                if (token == "" || Array.IndexOf(Stopwords, token) != -1)
                    tokens.Remove(token);
            }
        }

        public static bool IsBlankLine(String input)
        {
            Regex blankLineReg = new Regex("^[' ']*$");
            return blankLineReg.IsMatch(input);
        }

        public static String NonwordsFilter(String input)
        {
            Regex wordReg = new Regex("[^a-z]");
            return wordReg.Replace(input, " ");
        }

        public static String UppercaseFilter(String input)
        {
            return input.ToLower();
        }

    }
}